package com.yxq.mdt.app.modules.splash.model;

import com.yxq.mdt.app.base.RespBase;
import com.yxq.mdt.app.base.ibase.IBaseModel;
import com.yxq.mdt.app.modules.main.bean.NameAndPhoneBean;
import com.yxq.mdt.app.modules.main.model.AppApi;
import com.yxq.mdt.app.net.ApiModel;
import com.yxq.mdt.app.net.BaseObserver;
import com.yxq.mdt.app.net.RetrofitFactory;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import retrofit2.Retrofit;

/**
 * ================================================
 *
 * @function <p>
 * Created by yd on 2019-07-22
 * ================================================
 */
public class SplashModel implements IBaseModel {

    public static void getNameAndPhone(ApiModel.CommonCallback<NameAndPhoneBean> callback) {
        RetrofitFactory.getPMRetrofit().create(AppApi.class)
                .getNameAndPhone()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<RespBase<NameAndPhoneBean>>() {
                    @Override
                    public void onFailure(Throwable e, boolean isNetWorkError) {
                        callback.onError(e.getMessage());
                    }

                    @Override
                    public void onSuccess(RespBase<NameAndPhoneBean> respBase) {
                        callback.onSuccess(respBase.getData());
                    }
                });
    }

    @Override
    public void onDestroy() {

    }
}
